package com.chj.chap05.memleak;

/**
 * 自定义一个栈
 */
public class StackDemo {
    public Object[] elements;// 数组来保存
    private int size =0;
    private static final int Cap = 16;
    public StackDemo() {
        this.elements = new Object[Cap];
    }
    // 入栈
    public void push(Object o){
        elements[size] = o;
        size++;
    }
    // 出栈
    public Object pop(){
        size = size -1;
        Object o = elements[size];
        elements[size] = null; // 让GC 回收掉
        return o;
    }

}
